/*
   Copyright (c) [2023] [魔凤啸天]
   [MFUI] is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
            http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details.  
*/
#pragma once
#include "core.hpp"

namespace MFUI{
	class Layout:public CacheNode{
		protected:
		SDL_Color background;
		~Layout()override;
		//texture=nullptr draw时重置（如有需要）
		Layout(SDL_Color background,std::initializer_list<Node*>& children);

		public:
		bool confirmdraw()override;
		void setbackground(SDL_Color color);
		void removechild(Window* w,size_t index)override;
		void removechildren(Window* w,size_t start,size_t end)override;
		void popchildren(Window* w,size_t n)override;
		void addchild(Window* w,Node* n)override;
		void addchildren(Window* w,std::initializer_list<Node*> l)override;
		void insertchild(Window* w,Node* n,size_t index)override;
		void insertchildren(Window* w,std::initializer_list<Node*> l,size_t index)override;
		void swapchild(size_t a,size_t b)override;
	};
	class BoxLayout:public Layout{
		protected:
		~BoxLayout()override;
		float lmargin,rmargin,tmargin,bmargin;//itemsize重绘时计算
		float sep;//0~1
		BoxLayout(SDL_Color background,float tmargin,float bmargin,float lmargin,
		float rmargin,float sep,std::initializer_list<Node*>& children);
		public:
		void setmargin(float t,float b,float l,float r);
		void setseparate(float sep);
	};
	class VBoxLayout:public BoxLayout{
		public:
		void draw(Renderer* r,bool updatecache)override;
		//margin和sep均为0~1比例 基准是控件原尺寸
		VBoxLayout(SDL_Color background,float tmargin,float bmargin,float lmargin,
		float rmargin,float sep,std::initializer_list<Node*> children);
	};
	class HBoxLayout:public BoxLayout{
		public:
		void draw(Renderer* r,bool updatecache)override;
		//margin和sep均为0~1比例 基准是控件原尺寸
		HBoxLayout(SDL_Color background,float tmargin,float bmargin,float lmargin,
		float rmargin,float sep,std::initializer_list<Node*> children);
	};
	class VSepLayout:public BoxLayout{
		public:
		void draw(Renderer* r,bool updatecache)override;
		//上下切分 高度为sep margin和sep均为0~1比例 基准是控件原尺寸
		VSepLayout(SDL_Color background,float tmargin,float bmargin,float lmargin,
		float rmargin,float sep,std::initializer_list<Node*> children);
	};
	class HSepLayout:public BoxLayout{
		public:
		void draw(Renderer* r,bool updatecache)override;
		//左右切分 宽度为sep margin和sep均为0~1比例 基准是控件原尺寸
		HSepLayout(SDL_Color background,float tmargin,float bmargin,float lmargin,
		float rmargin,float sep,std::initializer_list<Node*> children);
	};
}